package cn.itcast.activiti.servlet.processinstance;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.runtime.ProcessInstance;

import cn.itcast.activiti.common.ProcessEngineUtils;

@WebServlet("/startProcessInstanceByKey.action")
public class StartProcessInstanceByKeyServlet extends HttpServlet{

	private static final long serialVersionUID = 1445744924777464941L;

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String pdKey=request.getParameter("pdKey");
		/** 获取流程引擎 */
		ProcessEngine pe=ProcessEngineUtils.getProcessEngine();
		/** 获取运行时服务 */
		RuntimeService rs=pe.getRuntimeService();
		/** 根据流程定义的id启动流程实例 */
		ProcessInstance pi=rs.startProcessInstanceByKey(pdKey);
		System.out.println(pi.getId());
		
		response.sendRedirect(request.getContextPath()+"/queryProcessDefinition.action");
	
	}

}
